//import java.text.SimpleDateFormat;
import com.rabbitmq.client.*;
//import java.util.Calendar;


public class rabbit_send {
	
	//private static final String EXCHANGE_NAME = "savegroup";

	  public static void main(String[] argv) throws Exception {

		  //Assert.assertEquals(jct.verbose.intValue(), 2);

		  //String hostname = "rp-1"; 
		  //String QUEUE_NAME = "savegroups_good"; //=="two"
		  //String message = "savegroup good sps";
		  //String time2live = "500000";
		  
		  String hostname = argv[0]; 
		  String QUEUE_NAME = argv[1]; //=="two"
		  String message = argv[2];
		  //String time2live = argv[3];
		
		  //String time2live = "5000";
		  
		//  int t2l = Integer.parseInt(time2live) * 60;
		  //int t2l = time2live * 60;
		   
		  //time2live = String.valueOf(t2l);
	    ConnectionFactory factory = new ConnectionFactory();
	    factory.setHost(hostname);
	    factory.setVirtualHost("backup");
	    factory.setPassword("networker");
	    factory.setUsername("backup");
	    //factory.setPort(80);
	    
	    //factory.setConnectionTimeout(500);
	    Connection connection = factory.newConnection();
	    Channel channel = connection.createChannel();

	    AMQP.BasicProperties properties = new AMQP.BasicProperties();
	    //properties.setExpiration(time2live);
	    properties.setDeliveryMode(2);
	    
	    //channel.exchangeDeclare(EXCHANGE_NAME, "direct");
	    boolean durable = true;
	    channel.queueDeclare(QUEUE_NAME, durable, false, false, null);
	    
	    int count = 1;
        while (count < 2) {
            //System.out.println("Count is: " + count);
            count++;
        
            //String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime());
	    
            //String message = "Hello World! from java " + timeStamp;
            channel.basicPublish("", QUEUE_NAME, properties, message.getBytes());
           // channel.basicPublish("", QUEUE_NAME, properties, message.getBytes());
	    
            System.out.println(" [x] Sent '" + message + "'");
            //Thread.sleep(10);
        }
	    channel.close();
	    connection.close();
	    System.out.println("Done");
	  }

	  
	  
}

